<?php
/**
 * Created by PhpStorm.
 * User: 勇林
 * Date: 2015/12/11
 * Time: 15:41
 */

namespace app\api\controllers;


use app\models\Course;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
use app\api\Response;

class CourseController extends Controller
{

    public function actionList($pageNow, $pageSize){

        $list = Course::getList($pageNow, $pageSize);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($list));
    }

    public function actionDetail($id){

        $detail = Course::findOne(['id'=>$id]);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($detail));
    }
/**
     * 搜索功能
     * @param type $coursename
     */
    public function actionSearch($coursename){
         $coursenames= Course::find()
    ->where(['or',['like','teacher',$coursename],['like','coursename',$coursename]])
              ->limit(10)
              ->all();
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($coursenames));
    }
}